home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER04.DOC < prev    next >
Encoding:
Text File  |  1993-10-02  |  11.9 KB  |  309 lines

  1. Chapter 4
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Coordinate Systems
  8.  
  9. 60   Fastgraph User's Guide
  10.  
  11.  
  12.  
  13. Overview
  14.  
  15.      Fastgraph uses three coordinate systems to perform text and graphics
  16. output.  These coordinate systems are character space, screen space, and
  17. world space.  The world space coordinate system is not available with
  18. Fastgraph/Light.
  19.  
  20.  
  21. Character Space
  22.  
  23.      The coordinate system used for displaying characters is called character
  24. space.  Fastgraph uses character space for displaying characters in both text
  25. and graphics video modes.  It can be thought of as a grid of rows and
  26. columns, with each cell in the grid holding one character.  Each cell is
  27. identified by its unique (row,column) integer coordinates.  The rows and
  28. columns are numbered starting at zero; the origin is always the upper left
  29. corner of the screen.  For example, in the 80-column by 25-row text modes (2,
  30. 3, and 7), the default (row,column) coordinates of the screen corners are
  31. shown in the following diagram.
  32.  
  33.                             (0,0)           (0,79)
  34.  
  35.  
  36.                             (24,0)         (24,79)
  37.  
  38. The number of rows and columns depends on the video mode, as shown in the
  39. following table.  For graphics modes, the table also includes the width and
  40. height in pixels of a character cell.
  41.  
  42.                            Mode                 Char. Char.
  43.                           Number  Columns Rows  Width Height
  44.  
  45.                              0      40     25
  46.                              1      40     25
  47.                              2      80     25
  48.                              3      80     25
  49.                              4      40     25     8     8
  50.                              5      40     25     8     8
  51.                              6      80     25     8     8
  52.                              7      80     25
  53.                              9      40     25     8     8
  54.                             11      80     25     9    14
  55.                             12      40     25     8     8
  56.                             13      40     25     8     8
  57.                             14      80     25     8     8
  58.                             15      80     25     8    14
  59.                             16      80     25     8    14
  60.                             17      80     30     8    16
  61.                             18      80     30     8    16
  62.                             19      40     25     8     8
  63.                             20      40     25     8     8
  64.                             21      40     50     8     8
  65.                             22      40     30     8     8
  66.  
  67.                                            Chapter 4:  Coordinate Systems   61
  68.  
  69.  
  70.                             23      40     60     8     8
  71.                             24      80     25     8    16
  72.                             25      80     30     8    16
  73.                             26      100    37     8    16
  74.                             27      128    48     8    16
  75.                             28      100    37     8    16
  76.                             29      128    48     8    16
  77.  
  78.      Fastgraph includes two routines, fg_getmaxx and fg_getmaxy, that
  79. respectively return the maximum column and row numbers in text modes.
  80. Example 4-1 demonstrates these two routines in a text mode.  The program uses
  81. fg_getmaxx and fg_getmaxy to obtain the maximum column and row numbers in
  82. mode 3.  It then displays these values (79 and 24).
  83.  
  84.                                  Example 4-1.
  85.  
  86.                     #include <fastgraf.h>
  87.                     #include <stdio.h>
  88.                     void main(void);
  89.  
  90.                     void main()
  91.                     {
  92.                        int max_col;
  93.                        int max_row;
  94.                        int mode;
  95.  
  96.                        mode = fg_getmode();
  97.                        fg_setmode(3);
  98.  
  99.                        max_col = fg_getmaxx();
  100.                        max_row = fg_getmaxy();
  101.  
  102.                        fg_setmode(mode);
  103.                        fg_reset();
  104.  
  105.                        printf("Last col = %d\n",max_col);
  106.                        printf("Last row = %d\n",max_row);
  107.                     }
  108.  
  109.  
  110.  
  111. Screen Space
  112.  
  113.      Screen space is one of two available coordinate systems in graphics
  114. modes.  It uses the physical device coordinates.  Screen space can be thought
  115. of as a grid of rows and columns, with each unit in the grid holding one
  116. pixel.  Each pixel is identified by its unique (x,y) integer coordinates.
  117. The pixel rows and columns are numbered starting at zero; the origin is
  118. always the upper left corner of the screen.  For example, in the 320 by 200
  119. graphics modes, the (x,y) coordinates of the screen corners are shown in the
  120. following diagram.
  121.  
  122.                             (0,0)          (319,0)
  123.  
  124.                             (0,199)      (319,199)
  125.  
  126. 62   Fastgraph User's Guide
  127.  
  128.  
  129.  
  130.  
  131.      The Fastgraph routines fg_getmaxx and fg_getmaxy return the maximum x
  132. and y screen coordinates when used in graphics modes, as shown in example
  133. 4-2.  The program uses fg_getmaxx and fg_getmaxy to obtain the maximum x and
  134. y coordinates in the standard CGA four-color graphics mode (mode 4).  It then
  135. displays these values (319 and 199).
  136.  
  137.                                  Example 4-2.
  138.  
  139.                       #include <fastgraf.h>
  140.                       #include <stdio.h>
  141.                       void main(void);
  142.  
  143.                       void main()
  144.                       {
  145.                          int maxx;
  146.                          int maxy;
  147.                          int mode;
  148.  
  149.                          mode = fg_getmode();
  150.                          fg_setmode(4);
  151.  
  152.                          maxx = fg_getmaxx();
  153.                          maxy = fg_getmaxy();
  154.  
  155.                          fg_setmode(mode);
  156.                          fg_reset();
  157.  
  158.                          printf("(%d,%d)\n",maxx,maxy);
  159.                       }
  160.  
  161.  
  162.  
  163. World Space
  164.  
  165.      World space is the other available coordinate system in graphics modes.
  166. It utilizes user-defined floating point coordinates.  Fastgraph translates
  167. world space coordinates into physical device coordinates (screen space), and
  168. because of this it is somewhat slower than using screen space.  World space
  169. can be thought of as a standard cartesian plane extending from the lower left
  170. corner of the screen.
  171.  
  172.      Any program that uses world space coordinates must first initialize
  173. Fastgraph's internal world space parameters.  The Fastgraph routine fg_initw
  174. is provided for this purpose.  The fg_initw routine has no arguments and must
  175. be called before any other routine that uses world space coordinates.
  176.  
  177.      The next step in using world space is to use the Fastgraph routine
  178. fg_setworld to define the world space coordinates of the screen edges.  The
  179. fg_setworld routine has four floating-point arguments -- the minimum x
  180. coordinate (left edge), the maximum x coordinate (right edge), the minimum y
  181. coordinate (bottom edge), and the maximum y coordinate (top edge).  For
  182. example, if you define the world space coordinates with the statement
  183.  
  184.                        fg_setworld(-10.0,10.0,0.0,2.5);
  185.                                            Chapter 4:  Coordinate Systems   63
  186.  
  187.  
  188.  
  189. the (x,y) coordinates of the screen corners would be defined as shown in the
  190. following diagram.
  191.  
  192.                             (-10.0,2.5) (10.0,2.5)
  193.  
  194.  
  195.                             (-10.0,0.0) (10.0,0.0)
  196.  
  197. Fastgraph includes a routine fg_getworld that returns the world space
  198. extremes as defined in the most recent call to fg_setworld.
  199.  
  200.      Example 4-3 uses fg_setworld and fg_getworld to illustrate an
  201. interesting application of world space.  This program calls another routine
  202. named redraw (not shown) that erases the screen and draws a certain image
  203. using world space coordinates.  The program draws the image, waits for a
  204. keystroke, reduces the world space by a factor of two in each direction, and
  205. then draws the image again.  This produces a zoom effect in which the image
  206. appears twice as large as it was originally.
  207.  
  208.                                  Example 4-3.
  209.  
  210.               #include <fastgraf.h>
  211.               #include <stdio.h>
  212.               #include <stdlib.h>
  213.               void main(void);
  214.               void redraw(void);
  215.  
  216.               void main()
  217.               {
  218.                  int new_mode, old_mode;
  219.                  double xmin, xmax, ymin, ymax;
  220.  
  221.                  old_mode = fg_getmode();
  222.                  new_mode = fg_automode();
  223.  
  224.                  if (new_mode == 0) {
  225.                     printf("This program requires graphics.\n");
  226.                     exit(1);
  227.                     }
  228.  
  229.                  fg_setmode(new_mode);
  230.                  fg_initw();
  231.  
  232.                  fg_setworld(0.0,40.0,0.0,30.0);
  233.                  redraw();
  234.                  fg_waitkey();
  235.  
  236.                  fg_getworld(&xmin,&xmax,&ymin,&ymax);
  237.                  fg_setworld(0.0,xmax*0.5,0.0,ymax*0.5);
  238.                  redraw();
  239.                  fg_waitkey();
  240.  
  241.                  fg_setmode(old_mode);
  242.  
  243. 64   Fastgraph User's Guide
  244.  
  245.  
  246.                  fg_reset();
  247.               }
  248.  
  249.  
  250. Conversion Routines
  251.  
  252.      Sometimes it's necessary to convert coordinates between character space,
  253. screen space, and world space.  Fastgraph includes eight conversion routines,
  254. four for x coordinates and four for y coordinates, to perform such
  255. conversions.  These routines return the translated coordinate as their
  256. function value.
  257.  
  258.      The fg_xalpha and fg_yalpha routines convert screen space coordinates to
  259. character space.  The fg_xalpha routine converts a screen space x coordinate
  260. to the character space column that contains the coordinate.  Similarly, the
  261. fg_yalpha routine converts a screen space y coordinate to the character space
  262. row that contains the coordinate.
  263.  
  264.      The fg_xconvert and fg_yconvert routines convert character space
  265. coordinates to screen space.  The fg_xconvert routine converts a character
  266. space column to the screen space coordinate of its leftmost pixel.
  267. Similarly, the fg_yconvert routine converts a character space row to the
  268. screen space coordinate of its top (lowest-numbered) pixel.
  269.  
  270.      The fg_xscreen and fg_yscreen routines convert world space coordinates
  271. to screen space.  The fg_xscreen routine translates x coordinates, while the
  272. fg_yscreen routine translates y coordinates.  Conversely, the fg_xworld and
  273. fg_yworld routines convert screen space coordinates to world space.  The
  274. fg_xworld routine translates x coordinates, while the fg_yworld routine
  275. translates y coordinates.
  276.  
  277.  
  278. Summary of Coordinate Routines
  279.  
  280.      This section summarizes the functional descriptions of the Fastgraph
  281. routines presented in this chapter.  More detailed information about these
  282. routines, including their arguments and return values, may be found in the
  283. Fastgraph Reference Manual.
  284.  
  285.      FG_GETMAXX returns the maximum x coordinate in screen space when used in
  286. a graphics mode.  It returns the maximum column number in character space
  287. when used in a text mode.
  288.  
  289.      FG_GETMAXY returns the maximum y coordinate in screen space when used in
  290. a graphics mode.  It returns the maximum row number in character space when
  291. used in a text mode.
  292.  
  293.      FG_GETWORLD returns the current world space limits, as defined in the
  294. most recent call to fg_setworld.
  295.  
  296.      FG_INITW initializes Fastgraph's internal parameters for world space.
  297. This routine must be called once, before any other routine that uses world
  298. coordinates.
  299.  
  300.      FG_SETWORLD defines the world space coordinates that correspond to the
  301. physical edges of the screen.
  302.                                            Chapter 4:  Coordinate Systems   65
  303.  
  304.  
  305.  
  306.      FG_XALPHA and FG_YALPHA convert screen space coordinates to character
  307. space.
  308.  
  309.      FG_XCONVERT and FG_YCONVERT convert character space coordinates to
  310. screen space.
  311.  
  312.      FG_XSCREEN and FG_YSCREEN convert world space coordinates to screen
  313. space.
  314.  
  315.      FG_XWORLD and FG_YWORLD convert screen space coordinates to world space.
  316. 66   Fastgraph User's Guide
  317.